package cn.cs.controller;//package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.service.AgentProductOrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/agentProductOrder")
public class AgentProductOrderController {
    @Resource
    private AgentProductOrderService service;
    /****
     * 获取产品列表（可根据分类获取）
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getPlatProList")
    @ResponseBody
    public Dto getPlatProList(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.getPlatProList(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 商品详情接口
     * @param
     * @param
     * @return
     */
    @RequestMapping("/platProInfo")
    @ResponseBody
    public Dto platProInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.platProInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * A级经销商下单接口
     * @param
     * @param
     * @return
     */
    @RequestMapping("/agentPlaceOrder")
    @ResponseBody
    public Dto agentPlaceOrder(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.agentPlaceOrder(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }


    /****
     * 获取订单列表接口
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getPlaceOrderList")
    @ResponseBody
    public Dto getPlaceOrderList(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.getPlaceOrderList(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }
    /****
     * 取消订单接口
     * @param
     * @param
     * @return
     */
    @RequestMapping("/canclePlaceOrder")
    @ResponseBody
    public Dto canclePlaceOrder(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.canclePlaceOrder(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 查看订货单详情
     * @param
     * @param
     * @return
     */
    @RequestMapping("/agentOrderDetail")
    @ResponseBody
    public Dto agentOrderDetail(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.agentOrderDetail(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }
}
